import time
from time import sleep

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
driver = webdriver.Edge()
driver.get("http://127.0.0.1/ranzhi/www/")
time.sleep(1)
# 用户名密码
driver.find_element("xpath",'//*[@id="account"]').send_keys("admin")
driver.find_element("xpath",'//*[@id="password"]').send_keys("123456")
# 点击登录
driver.find_element("xpath",'//*[@id="submit"]').click()
time.sleep(1)

# 点击后台管理
driver.find_element("xpath",'//*[@id="s-menu-superadmin"]/button/i').click()

# 切换到iframe
# 定位到iframe
iframe = driver.find_element("id","iframe-superadmin")
driver.switch_to.frame(iframe)

# 点击添加成员
driver.find_element("class name","shortcut.user").click()
# 角色下拉框
role = driver.find_element("id","role")
# 强转为select对象
s = Select(role)
# 获取所有的下拉选项的对象
ls = s.options
listtext = []
for i in ls:
    listtext.append(i.text)
print(listtext)
# 选中
s.select_by_visible_text(listtext[3])
time.sleep(10)
#回退
driver.back()
sleep(2)
#签退
driver.find_element("class name","sign.signout").click()
sleep(3)